export function resolveConstStyle(config) {
  const transConfig = {};
  const resolveFun = (obj, preName) => {
    try {
      Object.keys(obj).forEach((key) => {
        const nextName = `${preName}_${key}`;
        const value = obj[key];
        if (typeof value === 'string') {
          transConfig[nextName] = value;
        } else {
          resolveFun(value, nextName);
        }
      });
    } catch (error) {
      console.log(error);
    }
  };
  resolveFun(config, 'const');
  return transConfig;
}

export function appendStyles(styleConfigs) {
  try {
    Object.keys(styleConfigs).forEach((config) => {
      document.body.style?.setProperty(`--${config}`, styleConfigs[config]);
    });
  } catch (e) {
    console.log(e);
  }
}

// 转换小驼峰命名
const toLowerCamel = (name) => name.replace(/_(\w)/g, (all, letter) => letter.toUpperCase());

export function transObjectToLowerCamel(obj) {
  const newObject = {};
  try {
    Object.keys(obj).forEach((key) => {
      const value = obj[key];
      newObject[toLowerCamel(key)] = value;
    });
  } catch (error) {
    console.log(error);
  }
  return newObject;
}
